/* 
 * Enterprise Library Extensions - DI + ORM.
 * Copyright (C) 2006
 *
 * GNU General Public License
 *
 * This program is free software; you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 */
using System;
using ELE.Common.Util;

namespace ELE.EnterpriseLibrary.Messaging
{
  /// <summary>
  /// Defines the messages to use for source to the queue.
  /// 
  /// Author : Miguel Curi
  /// 
  /// </summary>
  public class MessageSourceInfo
  {
    /// <summary>
    /// Prefix for format name queues
    /// </summary>
    public const string PREFIX_FORMATNAME = @"FormatName:";
    /// <summary>
    /// Format name for direct os queue
    /// </summary>
    public const string PREFIX_DIRECT_OS = @"DIRECT=OS:";
    /// <summary>
    /// Prefix for private queues
    /// </summary>
    public const string PREFIX_PRIVATE = @"Private$";
    /// <summary>
    /// public queues
    /// </summary>
    public const string QUEUETYPE_PUBLIC = "public";
    /// <summary>
    /// identifies private queues
    /// </summary>
    public const string QUEUETYPE_PRIVATE = "private";
    private string mServer;
    private string mPath;
    private string mType;
    private string mId;
    private string mLabel;
    /// <summary>
    /// Default constructor
    /// </summary>
    public MessageSourceInfo()
    {
    }
    /// <summary>
    /// The Path or name of the messsage
    /// </summary>
    public string Path
    {
      get { return mPath; }
      set { mPath = value; }
    }
    /// <summary>
    /// The type of message which can be public or private
    /// </summary>
    public string Type
    {
      get { return mType; }
      set { mType = value; }
    }
    /// <summary>
    /// Name of the server
    /// </summary>
    public string ServerName
    {
      get { return mServer; }
      set { mServer = value; }
    }
    /// <summary>
    /// Unique identifier for this source or sink. If not set it returns the value from QueueName
    /// </summary>
    public string Id
    {
      get 
      { 
        if(string.IsNullOrEmpty(mId))
        {
          return QueueName;
        }
        return mId; 
      }
      set { mId = value; }
    }
    /// <summary>
    /// A label might be useful to query for queues in some cases.
    /// </summary>
    public string Label
    {
      get { return mLabel; }
      set { mLabel = value; }
    }
    /// <summary>
    /// The full name to the message queue
    /// </summary>
    public string QueueName
    {
      get
      {
        string qName = MessageEndPoint.ENDPOINT_LOCALHOST;
        if(StringUtils.NotEmpty(ServerName))
        {
          qName =  ServerName;
        }
        if(!(Type != null && Type.ToLower().Equals(QUEUETYPE_PUBLIC)))
        {
          qName = PREFIX_FORMATNAME + PREFIX_DIRECT_OS + qName + StringUtils.SLASH_FORWARD + PREFIX_PRIVATE;
        }
        qName += StringUtils.SLASH_FORWARD + this.Path;
        return qName;
      }
    }
    /// <summary>
    /// Is this defined as a public queue
    /// </summary>
    public bool IsPublicQueue
    {
      get { return this.Type != null && this.Type.ToLower().Equals(QUEUETYPE_PUBLIC); }
    }
  }
}
